#pragma once
#include <grpcpp/grpcpp.h>
#include "message.grpc.pb.h"
#include <mutex>

using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using message::GetResServerReq;
using message::GetResServerRsp;
using message::LoginReq;
using message::LoginRsp;
using message::StatusService;

class  ResServer {
public:
	ResServer():host(""),port(""),name(""),con_count(0){}
	ResServer(const ResServer& cs):host(cs.host), port(cs.port), name(cs.name), con_count(cs.con_count){}
	ResServer& operator=(const ResServer& cs) {
		if (&cs == this) {
			return *this;
		}

		host = cs.host;
		name = cs.name;
		port = cs.port;
		con_count = cs.con_count;
		return *this;
	}
	std::string host;
	std::string port;
	std::string name;
	int con_count;
};
class StatusServiceImpl final : public StatusService::Service
{
public:
	StatusServiceImpl();
	Status GetResServer(ServerContext* context, const GetResServerReq* request,
		GetResServerRsp* reply) override;
	Status Login(ServerContext* context, const LoginReq* request,
		LoginRsp* reply) override;
private:
	void insertToken(int uid, std::string token);
	ResServer getResServer();
	std::unordered_map<std::string, ResServer> _servers;
	std::mutex _server_mtx;

};

